package com.fishery.logistics.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fishery.logistics.entity.Station;
import com.fishery.logistics.mapper.StationMapper;
import com.fishery.logistics.service.StationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author run
 * @since 2021-01-23
 */
@Service
public class StationServiceImpl extends ServiceImpl<StationMapper, Station> implements StationService {

    @Autowired
    private StationMapper stationMapper;

    @Override
    public boolean createStation(Station station) {
        station.setId(null);
        return stationMapper.insert(station) > 0;
    }

    @Override
    public boolean updateStation(Station station) {
        return stationMapper.updateById(station) > 0;
    }

    @Override
    public boolean deleteStation(String stationId) {
        return stationMapper.deleteById(stationId) > 0;
    }

    @Override
    public List<Station> searchStationOfBase(String baseId) {
        Map<String,Object> map = new HashMap<>(1,1);
        map.put("base_id",baseId);
        return stationMapper.selectByMap(map);
    }

    @Override
    public IPage<Station> searchStationOfBase(String baseId, Integer page, Integer size) {
        Page<Station> stationPage = new Page<>(page,size);
        QueryWrapper<Station> wrapper = new QueryWrapper<>();
        wrapper.eq("base_id",baseId);
        return stationMapper.selectPage(stationPage,wrapper);
    }
}
